import { Controller, Post, Get, UseGuards, Body, Req } from '@nestjs/common'
import { AuthService } from './auth.service'
import { AuthGuard } from '@nestjs/passport'
import { JwtAuthGuard } from 'src/auth/jwt-auth.guard'
import { ApiTags } from '@nestjs/swagger'
import { loginDto } from './dto/login.dto'
import { Public } from 'src/core/decorators/public.decorator'
import { Roles } from 'src/core/decorators/role.decorator'
import { RoleGuard } from './role.guard'
import { RoleEnum } from 'src/core/decorators/enum/role.enum'


@ApiTags('验证')
@Controller('auth')
export class AuthController {
  constructor(private readonly authService: AuthService) { }

  // @Roles(RoleEnum.Admin, RoleEnum.Manager)
  //passport 本地登录策略
  @UseGuards(AuthGuard('local'))
  @Post('/login')
  async login(@Body() user: loginDto, @Req() req) {
    //req.user 是passport本地策略通过之后返回封装的
    return await this.authService.login(req.user)
  }

  @UseGuards(JwtAuthGuard)
  @Get('/getUserInfo')
  async getUserInfo(@Req() req) {
    return await this.authService.getUserInfoFn(req.user)
  }
}
